/*
 * @lc app=leetcode.cn id=1403 lang=typescript
 *
 * [1403] 非递增顺序的最小子序列
 */

// @lc code=start
function minSubsequence(nums: number[]): number[] {
    if (nums.length === 1) return nums;
    const sorted = nums.sort((a, b) => b - a);
    const sum = nums.reduce((col, cur) => col + cur, 0);
    const mid = sum / 2;
    let total = 0;
    let final: number[] = [];
    for (let i = 0; i < sorted.length; i++) {
        const element = sorted[i];
        total += element;
        final.push(element);
        if (total > mid) {
            return final;
        }
    }
    return final;
}
// @lc code=end
